var form;
var layer;
//页面初始化时加载Layui框架
layui.use(['form', 'layer'], function () {
    form = layui.form();
    layer = layui.layer;

    $("#selectUsers").click(function () {
        selectUsers();
        return false;
    });
});

function selectUsers() {
    var userIds = $("#userIds").val();
    openSelectUser(callBackUser, userIds);
}

/**
 * 打开人员选择
 */
function openSelectUser(callback, userIds) {
    var url = basePath + "jsp/user/selectUsersPage.jsp?defaultSelectId=" + userIds;
    var title = "选择警报接收人";
    layer.open({
        type: 2,
        title: title,
        area: ["40%", "90%"],
        shade: 0.3,
        offset: ['5px', '25%'],
        maxmin: true,
        content: url,
        btn: ['确定', '取消'],
        yes: function (index) {
            var userMap = art.dialog.data("userMap");
            callback(userMap);
            layer.close(index);
            return true;
        },
        zIndex: layer.zIndex,
        success: function (layero) {
            layer.setTop(layero); //弹窗置于最上层
        }
    });
}

/**
 * 回调选择人员
 */
function callBackUser(data) {
    if (data) {
        var userIds = [];
        var userNames = [];

        data.forEach(function (value) {
            userIds.push(value.Id);
            userNames.push(value.Name);

        });
        $("#userIds").val(userIds);
        var ids = "";
        for (var i = 0; i < userIds.length; i++) {
            ids = ids + userIds[i] + ",";
        }
        var paramData = {
            'ids': ids
        };
        $.ajax({
            url: basePath + "user/getUserName.action",
            type: "post",
            dataType: "text",
            data: paramData,
            success: function (data) {
                $("#warnUser").html(data);
            }
        });
    }
}

/**
 * 清空
 * @return
 */
function clearInput() {
    $("#userIds").val("");
    $("#warnUser").html("");
}